#ifndef GWRECTANGLE_H
#define GWRECTANGLE_H

#include "property/qtvariantproperty.h"
#include "property/qttreepropertybrowser.h"
#include "fileeditfactory.h"
#include "GraphicsType.h"
#include "GwGraphics_global.h"
#include <QGraphicsItem>
#include <property/qttreepropertybrowser.h>
#include <QTimeLine>


class GWGRAPHICS_EXPORT GwRectangle : public QObject,public QGraphicsItem
{
    Q_OBJECT
public:
    explicit GwRectangle();
    explicit GwRectangle(const GwRectangle &other);
    ~GwRectangle();
    // QGraphicsItem interface
    QRectF boundingRect() const;
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
    QRectF resizeHandle() ;
    void setName(QString name);
    void setGWFile(QString gwfile);
    QString getGWFile();
    void setPropertyTree(QtTreePropertyBrowser *treepro);
    void refreshProperty(QtProperty *item);
    void refreshPropertyList();
    void createPropertyList();
    GraphicsState state();
    QRectF rect();
    void setConfig();

    QGradient gradient(const QColor &color, const QRectF &rect, int time);

    GwRectangle& operator=(const GwRectangle &other);
    friend QDataStream & operator >> (QDataStream &in,GwRectangle& data);
    friend QDataStream & operator << (QDataStream &out,const  GwRectangle& data);

public slots:
    void propertyChanged(QtProperty *property, const QVariant &val);
    void movieRun(int frame);
    void setState(GraphicsState state);

signals:
    void roomClicked(QString filename);

private:
    int colldingCnt=0;
    QRectF m_oldrect;
    QRectF m_rect;
    QString name,gwfile;
    QPointF m_mouseOffset;
    bool m_resizeHandlePressed=false;
    GraphicsState itemstate=GState_OK;
    QList<QtProperty*> m_propertys;
    QMap<QtProperty*,QString> m_property_dic;
    QtVariantPropertyManager *m_pVarManager=NULL;
    QtVariantEditorFactory *m_pVarFactory=NULL;

    fileEditFactory *m_stringFactory=NULL;
    QtStringPropertyManager *m_stringManager=NULL;

    QTimeLine *movie;
    QColor rect_colour;



    int flash=0;
    int range=16;


    // QGraphicsItem interface
protected:
    void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
    void mousePressEvent(QGraphicsSceneMouseEvent *event);
    void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);

    // QGraphicsItem interface
public:
    bool collidesWithItem(const QGraphicsItem *other, Qt::ItemSelectionMode mode) const;
};

#endif // GWRECTANGLE_H
